package com.qiang.demo01;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Test02 {
    public static void main(String[] args) {
        Collection<String> str = new ArrayList<>();
        str.add("qwe");
        str.add("asd");
        str.add("zxc");
        str.add("rty");
       /* System.out.println(str);
        System.out.println("---==========");*/

        Iterator<String> it = str.iterator();//创建迭代
        while (it.hasNext()) {
            //System.out.println(it.hasNext());
            //System.out.println(it.next());
            String s = it.next();//利用迭代拿出每个元素
            //System.out.println(s);

            if ("qwe".equals(s)) {
                it.remove();
            }

        }
        System.out.println("---==========");
        System.out.println(str);
        System.out.println("---==========");

        for (String s1 : str) {
            //System.out.println(s1);
            if("zxc".equals(s1)){
                str.remove(s1);
            }
        }
        System.out.println(str);
        System.out.println("==========");
        for (String s : str) {
            if("asd".equals(s)){
                str.remove(s);
            }
            //System.out.println(s);
        }
        System.out.println(str);

    }
}
